//
//  UIBarButtonItem+Extensions.swift
//  weibo
//
//  Created by iobit on 2017/06/05.
//  Copyright © 2017 zhuxu. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    /// 抽取方法，创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize默认为16
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否加入返回图片按钮
    convenience init(title:String, fontSize:CGFloat = 16,target:Any?, action:Selector, isBack:Bool = false) {
        let btn:UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: UIControlState(rawValue: 0))//rawValue: 0表示默认状态
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        self.init(customView: btn)
    }
}
